var app = new Vue({
	el: '#app',
	data: {
		userMsg: {
			isLogin: false,
			id: null,
			account: null,
			name: null,
			headimg: null
		},
		newsList: [],
		moduleList: []
	},
	computed: {
		newsList2: function(){
			var ret = [];
			for (var i = 0; i < this.newsList.length; i++){
				ret.push(this.newsList[i]);
				if (ret.length == 11) {
					break;
				}
			} 
			return ret;
		}
	},
	methods: {
		logout: function(){
			var self = this;

			swal({ 
				title: "确定退出吗？", 
				type: "warning",
				showCancelButton: true, 
				confirmButtonColor: "#DD6B55",
				confirmButtonText: "确定", 
  				cancelButtonText: "取消"
			},function(){
				$.post("/api/logout",{},function(data,status){
					if (data.success = "ok") {
						self.getLoginStatus();
					}
				});
			});

		},
		getLoginStatus: function(){
			var self = this;
			$.get('/api/isLogin',function(data,status){
				if (data.success == "ok") {
					self.userMsg.isLogin = true;
					self.userMsg.name = data.result.name;
					self.userMsg.id = data.result.id;
					self.userMsg.account = data.result.account;
					self.userMsg.headimg = data.result.headimg;
				} else {
					self.userMsg.isLogin = false;
				}
			})
		},
		getNews: function(){
			var self = this;
			$.post('/api/getNewsList',function(data,status){
				if (data.success == "ok") {
					self.newsList = data.result;
				} else {
					swal("网络错误","请重试","error");
				}
			})
		},
		getModule: function(){
			var self = this;
			$.post('/api/getModule',function(data,status){
				if (data.success == "ok") {
					self.moduleList = data.result;
				} else {
					swal("网络错误","请重试","error");
				}
			})

		}
	},
	mounted: function(){
		this.getLoginStatus();
		this.getNews();
		this.getModule();
	}
})
